// JavaScript Document
$(function(){
	//数量加减
	$(document).on("click",".Decrease",function(){
		var obj=$(this);
		var p=obj.parents(".cart_num");
		var v=parseInt(p.find(".Amount").val());
		v=v-1;
		if(v>=0){
			$.get("/index.php?m=ymdian_order_cart&a=add&ajax=1",{object_id:p.attr("object_id"),shopid:p.attr("shopid"),productid:p.attr('productid'),amount:v},function(data){
				if(data.error){
					skyToast(data.message);
				}else{
					if(v==0){
						obj.parents(".showcart").find(".cart_icon").show();
						if(obj.parents(".cart_list").length>0){
							obj.parents("li").remove();
						}
						p.hide();
					}
					p.find(".Amount").val(v);
					$("#cart_num").html(data.data.num);
					botnav_cart_num();
					$("#cart_total_money").html(data.data.total_money);
					if(parseInt(data.data.total_money)>=qsjia){
						$("#shop_lt_qsjia").hide();
						$("#shop_gt_qsjia").show();
					}else{
						$("#shop_lt_qsjia").show();
						$("#shop_gt_qsjia").hide();
					}
					var ptm=obj.parents("li").find(".p_total_money");
					var pprice=obj.parents("li").find(".p_price").html();
					ptm.html(parseInt(pprice)*v);
				 
				 
				}
			},"json")
		}else{
			skyToast("数量不能少于1件");
		}
	});
	
	$(document).on("click",".Increase",function(){
		var obj=$(this);
		var p=obj.parents(".cart_num");
		var v=parseInt(p.find(".Amount").val());
		var nv=v+1;
		var scrollLeft = document.documentElement.scrollLeft || document.body.scrollLeft || 0,
			    scrollTop = document.documentElement.scrollTop || document.body.scrollTop || 0;
		var left=event.clientX + scrollLeft + "px";
		var top=event.clientY + scrollTop + "px";
		$.get("/index.php?m=ymdian_order_cart&a=add&ajax=1",{object_id:p.attr("object_id"),shopid:p.attr("shopid"),productid:p.attr('productid'),amount:nv},function(data){
			if(data.error){
				skyToast(data.message);
				if(v==0){
					obj.parents(".showcart").find(".cart_icon").show();
					p.hide();
				}
			}else{
				p.find(".Amount").val(nv);
				$("#flyItem").css({"visibility":"visible","left":left,"top":top});
				 
				$("#cart_num").html(data.data.num);
				$("#cart_total_money").html(data.data.total_money);
				botnav_cart_num();
				if(parseInt(data.data.total_money)>=qsjia){
						$("#shop_lt_qsjia").hide();
						$("#shop_gt_qsjia").show();
					}else{
						$("#shop_lt_qsjia").show();
						$("#shop_gt_qsjia").hide();
					}
				var ptm=obj.parents("li").find(".p_total_money");
				var pprice=obj.parents("li").find(".p_price").html();
				ptm.html(parseInt(pprice)*nv);
			 	
				if(typeof(myParabola)!="undefined"){
					myParabola.position().move(); 
				}
			}
		},"json")
		
		
	});
	
	$(document).on("click",".cart_del",function(){
		var obj=$(this);
		$.get("/index.php?m=ymdian_order_cart&a=delete&ajax=1&id="+$(this).attr("did"),function(data){
			if(data.error){
				
			}else{
				obj.parents("li").remove();
			 $("#cart_num").html(data.data.num);
			 botnav_cart_num();
			 $("#cart_total_money").html(data.data.total_money);
			}
		},"json")
		
	});
	
});
